package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketFeedbackExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.cskaoyan.util.StringUtil;
import com.cskaoyan.util.TransactionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class FeedbackServiceImpl implements FeedbackService {
    @Override
    public CommonData<MarketFeedback> query(Integer page, Integer limit, String sort, String order, String username, Integer id) {
        MarketFeedbackExample example = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = example.createCriteria();

        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        if (!StringUtil.isEmpty(username)) {
            criteria.andUsernameEqualTo(username);
        }

        criteria.andDeletedEqualTo(false);

        if (!StringUtil.isEmpty(sort) && !StringUtil.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        PageHelper.startPage(page, limit);

        MarketFeedbackMapper marketFeedbackMapper = TransactionUtil.getMapper(MarketFeedbackMapper.class);
        PageHelper.startPage(page, limit);
        List<MarketFeedback> marketFeedbacks = marketFeedbackMapper.selectByExample(example);
        return CommonData.data(new PageInfo(marketFeedbacks));
    }
}
